
package org.efficientsoap.test.deserializer;

import java.io.IOException;

import org.efficientsoap.client.IBodyDeserializer;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.efficientsoap.client.EfficientSoapFaultException;

import android.util.Log;

import org.efficientsoap.client.EfficientSoapDeserializer;
import org.efficientsoap.test.results.*;
import org.efficientsoap.test.datatypes.*;

/**
 * a parsing helper class for the output parameter capsulating Return TYPEs
 * using the EfficientSoap.org SOAP client library project.
 *
 *
 * @author Christian Rau
 */
public class GenerateComplexDataResponseDeserializer extends EfficientSoapDeserializer<GenerateComplexDataReturn> implements IBodyDeserializer<GenerateComplexDataReturn>{

	private static final String TAG = GenerateComplexDataResponseDeserializer.class.getSimpleName();

	private static final String _NAMESPACE = "http://efficietsoap.org/test/results";
	private GenerateComplexDataReturn generateComplexDataReturn;

	public GenerateComplexDataResponseDeserializer() throws XmlPullParserException{
	    super(); 
	}

	@Override
    public GenerateComplexDataReturn parseBody() throws IOException, XmlPullParserException, EfficientSoapFaultException
	{
		parser.require(XmlPullParser.START_TAG, getSoapNamespace(), "Body");
		parser.nextToken();

		skipWhitespace();
		// SOAP-fault handling
		if (parser.getEventType() == XmlPullParser.START_TAG && "Fault".equals(parser.getName())) {
				getFaultDeserializer().parseFault();
				return new GenerateComplexDataReturn();
		}
		//return type parsing
		else{
			parseGenerateComplexDataResponse();
		}

		skipWhitespace();
		parser.require(XmlPullParser.END_TAG, null, "Body");
		parser.nextToken();

		return generateComplexDataReturn;
	}

	void parseGenerateComplexDataResponse() throws IOException, XmlPullParserException, EfficientSoapFaultException
	{
		parser.require(XmlPullParser.START_TAG, _NAMESPACE, "generateComplexDataResponse");
		parser.nextToken();

		skipWhitespace();
		generateComplexDataReturn = MethodReturnTypesDeserializer.parseGenerateComplexDataReturn(this, "GenerateComplexDataReturn");

		skipWhitespace();
		parser.require(XmlPullParser.END_TAG, null, "generateComplexDataResponse");
		parser.nextToken();
	}
}

